package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Delivery;
import com.ruoyi.system.service.IDeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 发货记录Controller
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@RestController
@RequestMapping("/wms/delivery")
public class DeliveryController extends BaseController
{
    @Autowired
    private IDeliveryService deliveryService;

    /**
     * 查询发货记录列表
     */
    @PreAuthorize("@ss.hasPermi('wms:delivery:list')")
    @GetMapping("/list")
    public TableDataInfo list(Delivery delivery)
    {
        startPage();
        List<Delivery> list = deliveryService.selectDeliveryList(delivery);
        return getDataTable(list);
    }

    /**
     * 导出发货记录列表
     */
    @PreAuthorize("@ss.hasPermi('wms:delivery:export')")
    @Log(title = "发货记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Delivery delivery)
    {
        List<Delivery> list = deliveryService.selectDeliveryList(delivery);
        ExcelUtil<Delivery> util = new ExcelUtil<Delivery>(Delivery.class);
        util.exportExcel(response, list, "发货记录数据");
    }

    /**
     * 获取发货记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:delivery:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deliveryService.selectDeliveryById(id));
    }

    /**
     * 新增发货记录
     */
    @PreAuthorize("@ss.hasPermi('wms:delivery:add')")
    @Log(title = "发货记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Delivery delivery)
    {
        return toAjax(deliveryService.insertDelivery(delivery));
    }

    /**
     * 修改发货记录
     */
    @PreAuthorize("@ss.hasPermi('wms:delivery:edit')")
    @Log(title = "发货记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Delivery delivery)
    {
        return toAjax(deliveryService.updateDelivery(delivery));
    }

    /**
     * 删除发货记录
     */
    @PreAuthorize("@ss.hasPermi('wms:delivery:remove')")
    @Log(title = "发货记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deliveryService.deleteDeliveryByIds(ids));
    }

    /**
     * 查询运营商下拉树结构
     */
    @PreAuthorize("@ss.hasPermi('wms:history:list')")
    @GetMapping("/deptTree")
    public AjaxResult deptTree(SysDept dept) {
        return null;
        //return success(deptService.selectDeptTreeList(dept));
    }


    /**
     * 获取发货记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:delivery:query')")
    @GetMapping(value = "/getShipmentOrderId/{shipmentOrderId}")
    public AjaxResult getShipmentOrderId(@PathVariable("shipmentOrderId") Long shipmentOrderId)
    {
        Delivery delivery = deliveryService.selectDeliveryByshipmentOrderId(shipmentOrderId);
        return success(delivery);
    }
}
